import * as Router from 'koa-router';
import env from "./../config/env";
import { dingTalkApi } from 'dingtalk-app'

let router = new Router();
router.prefix('/api/auth')

.get('/login', async (ctx: Router.IRouterContext, next: any) => {
    let authCode: string = ctx.query.code;
    let authjson: any = await dingTalkApi.login(authCode, 'mobile', 'isAdmin', 'roles', 'avatar', 'department', 'isLeaderInDepts');
    ctx.body = authjson;
    await next();
})

.get('/getPcJsConfig', async (ctx: Router.IRouterContext, next: any) => {
    let config = await dingTalkApi.signature('', env.domain + (ctx.querystring ? `?${ctx.querystring}` : ""));
    ctx.body = config
    await next();
})

.get('/getJsConfig', async (ctx: Router.IRouterContext, next: any) => {
    let config = await dingTalkApi.signature();
    ctx.body = config
    ctx.status = 200;
    await next();
});

export default router